package cms.manage.template.value.impl;

import cms.bean.PageView;
import cms.bean.redEnvelope.GiveRedEnvelope;
import cms.bean.redEnvelope.ReceiveRedEnvelope;
import cms.bean.template.Forum;
import cms.manage.template.impl.RedEnvelopeTemplateManage;
import cms.manage.template.value.TplValueStrategy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

import static cms.common.SystemConstant.DisplayType.*;

@Service("红包")
public class RedEnvelopeStrategy implements TplValueStrategy {
    @Resource
    RedEnvelopeTemplateManage redEnvelopeTemplateManage;//红包 -- 模板方法实现

    @Override
    public Object doOperation(Forum forum, Map submitParameter, Map runtimeParameter) {
        if(forum.getForumChildType().equals("发红包内容")){
            if(forum.getDisplayType().equals(DISPLAY_ENTITYBEAN.getValue())){//实体对象
                GiveRedEnvelope value =  redEnvelopeTemplateManage.contentEntityBean(forum, submitParameter, runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("领取红包用户列表")){
            if(forum.getDisplayType().equals(DISPLAY_PAGE.getValue())){//分页
                PageView<ReceiveRedEnvelope> value = redEnvelopeTemplateManage.receiveRedEnvelopeUserPage(forum, submitParameter,runtimeParameter);
                return value;
            }
        }else if(forum.getForumChildType().equals("抢红包")){
            if(forum.getDisplayType().equals(DISPLAY_COLLECTION.getValue())){//集合
                Map<String,Object> value = redEnvelopeTemplateManage.addReceiveRedEnvelopeCollection(forum, submitParameter, runtimeParameter);
                return value;
            }
        }
        return null;
    }
}
